package xyz.yeidi.controller;

import xyz.yeidi.pojo.Deliveryaddress;
import xyz.yeidi.service.api.DeliveryAddressService;
import xyz.yeidi.utils.ServiceFactory;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @Author JIP
 * @Date 2021-08-06 12:19
 * @Version 1.0
 * @Describe :
 */
@WebServlet("/addAddress")
public class AddAddressServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        DeliveryAddressService deliveryAddressService = ServiceFactory.getDeliveryAddressService();
        PrintWriter out = response.getWriter();
        String contactName = request.getParameter("contactName");
        String contactSex = request.getParameter("contactSex");
        System.out.println(contactSex);
        String contactTel = request.getParameter("contactTel");
        String address = request.getParameter("address");
        String userId = request.getParameter("userId");
        Deliveryaddress deliveryaddress = new Deliveryaddress();
        deliveryaddress.setContactName(contactName);
        deliveryaddress.setContactSex(Integer.valueOf(contactSex));
        deliveryaddress.setContactTel(contactTel);
        deliveryaddress.setAddress(address);
        deliveryaddress.setUserId(Integer.valueOf(userId));
        boolean b = deliveryAddressService.addAddress(deliveryaddress);
        if(b){
            out.print("ok");
        }else{
            out.print("error");
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
